#!/usr/bin/python

import pygame
import sys


class Character(pygame.sprite.Sprite) :

	def __init__( self, position, file_name ) :
		
		pygame.sprite.Sprite.__init__(self)

		self.screen = pygame.display.get_surface().get_rect()
		self.old = (0, 0, 0, 0)
		self.image = pygame.image.load( file_name ).convert()
		self.rect = self.image.get_rect()
		self.rect.x = position[0]
		self.rect.y = position[1]

	def update( self, amount, restricted, block_size ):
		self.old = self.rect

		try : 
			print restricted.index([ ((self.rect.x + amount[0])/block_size), ((self.rect.y + amount[1])/block_size) ])
			print ([ ((self.rect.x + amount[0])/block_size), ((self.rect.y + amount[1])/block_size) ])
			print 'self.rect.x: ' + str(self.rect.x) + '   self.rect.y: ' + str(self.rect.y)
		#	if restricted.index([ ((self.rect.x + amount[0])%block_size), ((self.rect.y + amount[1])%block_size) ]) != 0 :
			print 'RESTRICTED!'
			self.rect.move( [0,0] )
		except :	
		#	print ([ ((self.rect.x + amount[0])/block_size), ((self.rect.y + amount[1])/block_size) ])
			self.rect = self.rect.move( amount )
			if self.rect.x < 0:
				self.rect.x = 0
			elif self.rect.x > (self.screen.width - self.rect.width) :
				self.rect.x = self.screen.width - self.rect.width
			if self.rect.y < 0 :
				self.rect.y = 0
			elif self.rect.y > (self.screen.height - self.rect.height) :
				self.rect.y = self.screen.height - self.rect.height

